package gatewinapp;

import org.apache.commons.lang.ArrayUtils;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Thach
 */
public class Query {
    private String[] array_query;
    private String[] array_title;
    private String[] array_and;
    private String[] array_or;
    private String[] array_not;
    private String queryString;
    
    public Query(String query)
    {
        this.array_query = query.split(" ");
        queryString = "content:\"" + this.array_query[0] + "\"";
        for(int i = 1; i < this.array_query.length; i++) {
            queryString += "OR content:\"" + this.array_query[i] + "\"";
        }
    }
    
    public Query(String title, String and, String or, String not)
    {
        array_title = title.split(" ");
        array_and = and.split(" ");
        array_or = or.split(" ");
        array_not = not.split(" ");
        array_query = (String[]) ArrayUtils.addAll(array_and, array_or);
        queryString = "";
        
        // title
        if(!title.equals("")) {
            queryString += "title:\"" + array_title[0] + "\"";
            for (int i = 1; i < array_title.length; i++) {
                queryString += "OR title:\"" + array_title[i] + "\"";
            }
        }
        
        // and
        if(!and.equals("")) {
            for (int i = 0; i < array_and.length; i++) {
                queryString += "+content:\"" + array_and[i] + "\"";
            }
        }
        
        // or
        if(!or.equals("")) {
            for (int i = 0; i < array_or.length; i++) {
                queryString += "OR content:\"" + array_or[i] + "\"";
            }
        }
        
        // not
        if(!not.equals("")) {
            for (int i = 0; i < array_not.length; i++) {
                queryString += "NOT content:\"" + array_not[i] + "\"";
            }
        }
    }
    
     //String  query = "+content:\"lack\"";
      //String  query = "+content:\"lack exhibition\" -content:\"USA\"";
     //String  query = "+content:\"lack\"+content:\"USA\"";
     //String  query = "+content:\"lack\" -content:\"USA\"";
   
    public String[] getArrayQuery()
    {
        return array_query;
    }
    
    public String createQueryString()
    {
        return queryString;
    }
}
